import SQLiteStorage from 'react-native-sqlite-storage';

export default class SQLiteHelper {
    constructor() {
        SQLiteStorage.DEBUG(true);
        this.database_name = 'mooc.db';
        this.database_version = '0.1';
        this.database_displayname = 'MOOC_DB';
        this.database_size = -1;
    }

    openDatabase() {
        return new Promise((resolve, reject) => {
            this.db = SQLiteStorage.openDatabase(
                this.database_name,
                this.database_version,
                this.database_displayname,
                this.database_size,
                () => {
                    resolve();
                },
                (err) => {
                    reject();
                });
        })
    }

    closeDatabase() {
        if (this.db) {
            this.db.close();
            this.onSuccess('close');
        } else {
            console.log("SQLiteStorage not open");
        }
    }

    onSuccess(msg) {
        console.log("SQLiteHelperSuccess " + msg);
    }

    onError(msg, err) {
        console.log("SQLiteHelperError " + msg, + err);
    }
};